<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Testing websockets</title>
</head>
<body>
	<div>
        <textarea name="text" id="text"  rows="3" cols="20"></textarea>
		<input type="submit" value="send" onclick="start()" />
	</div>
	<div id="messages"></div>
	<script type="text/javascript">
		var webSocket = new WebSocket('ws://localhost:8080/websockets/chat.ws?s=10000076&r=10000227&co=fcBCP7&source=1');
		//连接发生错误的回调方法
		webSocket.onerror = function(event) {
			console.log("onerror"+event);
			alert("连接失败");
		};
		//连接成功建立的回调方法
		webSocket.onopen = function(event) {
			console.log("onopen");
			document.getElementById('messages').innerHTML 
				= 'Connection established';
		};
		//接收到消息的回调方法
		webSocket.onmessage = function(event) {
			console.log("onmessage");
			document.getElementById('messages').innerHTML 
				+= '<br />' + event.data;
		};
		function start() {
            var text =document.getElementById('text').value;
			webSocket.send(text);
			return false;
		}
	</script>
</body>
</html>